#include "OGLRenderer.h"

OGLRenderer::OGLRenderer()
{
	// Create the window control first as it initializes GLEW and GLFW
	windowControl = new OGLWindowControl();
	viewControl = new OGLViewControl();
}

OGLRenderer::~OGLRenderer()
{
	delete viewControl;
	delete windowControl;

	viewControl = NULL;
	windowControl = NULL;
}

OGLResult OGLRenderer::Launch()
{
	OGLResult retval = init();
	if(retval != OGL_SUCCESS)
		return retval;

	LoopInitialize();
	while((glfwGetKey(GLFW_KEY_ESC) != GLFW_PRESS) 
		&& glfwGetWindowParam(GLFW_OPENED))
	{
		LoopIterate();
		LoopUpdate();
	}

	LoopComplete();
	retval = cleanup();

	return retval;
}

OGLResult OGLRenderer::init()
{
	// Start OGL Controls
	OGLResult retval = windowControl->StartControl();
	if(retval != OGL_SUCCESS)
		return retval;
	
	return viewControl->StartControl();
}

OGLResult OGLRenderer::cleanup()
{
	// Stop OGL Controls
	OGLResult retval = windowControl->StopControl();
	if(retval != OGL_SUCCESS)
		return retval;
	
	return viewControl->StopControl();
}

void OGLRenderer::LoopInitialize(){}
void OGLRenderer::LoopIterate(){}
void OGLRenderer::LoopUpdate(){}
void OGLRenderer::LoopComplete(){}